const mongoose = require('mongoose')
const { formatDate } = require('../utils/utils')
const schema = new mongoose.Schema({
  userId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
    required: true,
  },
  articleId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Article',
    required: true,
  },
  likedAt: {
    type: mongoose.SchemaTypes.Date,
    default: Date.now,
    get(val) {
      return formatDate(new Date(val), 'yyyy年MM月dd日 hh:mm:ss')
    },
  },
})
schema.set('toJSON', { getters: true, versionKey: false, virtuals: true })
module.exports = mongoose.model('Like', schema)
